using System;
using System.Collections.Generic;
using UnityEngine;

public class GamePanelModel:ModelBase
{
    PlayerData p_data;
    Dictionary<string,PlayerData> dic = new Dictionary<string, PlayerData>();
    public static string m_name;
    public int countDownTimeNum,bossNowLevelNum;
    public Dictionary<string, PlayerData> GetAllData()
    {
        return dic;
    }
    public GamePanelModel(string name):base(name)
    {
        m_name = name;
        countDownTimeNum=90;
        bossNowLevelNum=600;
        
    } 
    public int GetCountDownTimeNum(){
        return countDownTimeNum;    
    }
    public int GetBossNowLevelNum(){
        return bossNowLevelNum;
    }
    public void SetCountDownTimeNum(int num){
        countDownTimeNum=num;
    }
    public void SetBossNowLevelNum(int num){
        bossNowLevelNum=num; 
    }
    public void RefurePlayerData(PlayerData data)
    {
        p_data = data;
        if(dic.ContainsKey(data.name)){
            dic[data.name] = p_data; 
        }else{
            dic.Add(data.name,p_data);
        }
        MessageCenter.Ins.BuredMess(MessId.RefureRankingList,dic);
    }
    public PlayerData GetRoleData(string name)
    {
        PlayerData data;
        if (dic.ContainsKey(name))
        {
            data= dic[name];
        }
        else
        {
            dic.Add(name, new PlayerData()
            {
                name = name+ DateTime.Now.Ticks,
                nowLevel = UnityEngine.Random.Range(p_data.nowLevel-20<=0?1: p_data.nowLevel - 20, p_data.nowLevel +20)
            });
            data= dic[name];
            MessageCenter.Ins.BuredMess(MessId.RefureRankingList, dic);
        }
        return data;
    }
    public void AddRoleLevel(string name,int num)
    {
        if (!dic.ContainsKey(name))
        {
            dic.Add(name, new PlayerData()
            {
                name = name,
                nowLevel = 0
            });
        }
        dic[name].nowLevel += num;
        MessageCenter.Ins.BuredMess(MessId.RefureRankingList, dic);
    }
    public void RemoveRoleData(string name)
    {
        if (dic.ContainsKey(name))
        {
            dic.Remove(name);
        }
    }
    public void ClaerData()
    {
        dic.Clear();
    }
}
